import {
	createStore,
	combineReducers,
	applyMiddleware,
	compose
} from 'redux';

import {
	reducer as todoReducer
} from './todos';
import {
	reducer as filterReducer
} from './filter';

const win = window;

const reducer = combineReducers({
	todos: todoReducer,
	filter: filterReducer
});

const middlewares = [];

if (process.env.NODE_ENV !== 'production') {
	const Perf = require('react-addons-perf');
	win.Perf = Perf;

	middlewares.push(require('redux-immutable-state-invariant').default());
}

const storeEnhancers = compose(
	applyMiddleware(...middlewares),
	(win && win.devToolsExtension) ? win.devToolsExtension() : (f) => f
);

const initialState = {
	todos: [{
		id: 0,
		text: 'First',
		completed: true
	}, {
		id: 1,
		text: 'Second',
		completed: false
	}, {
		id: 2,
		text: 'Third',
		completed: true
	}]
}

export default createStore(reducer, initialState, storeEnhancers)